package com.example.yinweiapplication.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import android.widget.Toast;

import com.example.yinweiapplication.R;
import com.example.yinweiapplication.config.UrlsConfig;
import com.example.yinweiapplication.ui.MainActivity;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * Created by 刘方 on 2015/7/6.
 */
public class MyFragment extends BaseFragment {
    @ViewInject(R.id.telephoneNum_myFragment)
    private EditText telephoneNum;
    @ViewInject(R.id.passWord_myFragment)
    private EditText passWord;
    private HttpUtils httpUtils;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.my_fragment_layout,container,false);
        ViewUtils.inject(getActivity(),view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
//        UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.login");
//        UMSocialService.doOauthVerify(Context context , SHARE_MEDIA platform , UMAuthListener listener)
        httpUtils = new HttpUtils();

    }

    @OnClick(R.id.login_button_myFragment)
    public void login(View v){
        String phone = telephoneNum.getText().toString();
        String password = passWord.getText().toString();
        if(phone!=null&&password!=null){
            httpUtils.send(HttpRequest.HttpMethod.GET, UrlsConfig.LOGIN, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {

                }

                @Override
                public void onFailure(HttpException e, String s) {

                }
            });
        }else{
            Toast.makeText(getActivity(),"信息不完整",Toast.LENGTH_SHORT);
        }
    }

    @OnClick(R.id.back)
    public void back(View v){
        getActivity().startActivity(new Intent(getActivity(),MainActivity.class));
    }

    @OnClick({R.id.weixin,R.id.QQ,R.id.xinlang})
    public void logInByOther(View v){
        switch (v.getId()){
            case R.id.weixin:

                break;
            case R.id.QQ:

                break;
            case R.id.xinlang:
                Platform weibo = ShareSDK.getPlatform(getActivity(), SinaWeibo.NAME);
                weibo.setPlatformActionListener(paListener);
                weibo.authorize();
//移除授权
//weibo.removeAccount();
                break;
        }

    }

}
